@model AdminIndexViewModel
@inject ShellSettings ShellSettings
@using Microsoft.AspNetCore.Http;
@using OrchardCore.Data;
@using OrchardCore.Environment.Shell.Models
@using OrchardCore.Environment.Shell
@using System.Collections.Generic
@using System.Net

@{
    List<SelectListItem> tenantStates = new List<SelectListItem>() {
new SelectListItem() { Text = T["All states"].Value, Value = TenantsFilter.All.ToString() },
new SelectListItem() { Text = T["Running"].Value, Value = TenantsFilter.Running.ToString() },
new SelectListItem() { Text = T["Disabled"].Value, Value = TenantsFilter.Disabled.ToString() },
new SelectListItem() { Text = T["Uninitialized"].Value, Value = TenantsFilter.Uninitialized.ToString() }
};

    List<SelectListItem> tenantSorts = new List<SelectListItem>() {
new SelectListItem() { Text = T["Sort by name"].Value, Value = TenantsOrder.Name.ToString() },
new SelectListItem() { Text = T["Sort by state"].Value, Value = TenantsOrder.State.ToString() }
};

    List<SelectListItem> tenantActions = new List<SelectListItem>() {
new SelectListItem() { Text = T["Disable"].Value, Value = BulkAction.Disable.ToString() },
new SelectListItem() { Text = T["Enable"].Value, Value = BulkAction.Enable.ToString() }
};
}

@functions {
public string GetTenantUrl(ShellSettingsEntry shellSettingsEntry)
{
    ShellSettings tenantShellSettings = shellSettingsEntry.ShellSettings;
    var requestHostInfo = Context.Request.Host;

    var tenantUrlHost = tenantShellSettings.RequestUrlHost?.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? requestHostInfo.Host;
    if (requestHostInfo.Port.HasValue)
    {
        tenantUrlHost += ":" + requestHostInfo.Port;
    }

    var pathBase = Context.Request.PathBase.Value ?? string.Empty;

    if (!string.IsNullOrEmpty(ShellSettings.RequestUrlPrefix))
    {
        var prefix = "/" + ShellSettings.RequestUrlPrefix;

        if (pathBase.EndsWith(prefix))
        {
            pathBase = pathBase.Substring(0, pathBase.Length - prefix.Length);
        }
    }

    var result = $"{Context.Request.Scheme}://{tenantUrlHost}{pathBase}";

    if (!string.IsNullOrEmpty(tenantShellSettings.RequestUrlPrefix))
    {
        result += "/" + tenantShellSettings.RequestUrlPrefix;
    }

    if (!string.IsNullOrEmpty(shellSettingsEntry.Token))
    {
        result += "?token=" + WebUtility.UrlEncode(shellSettingsEntry.Token);
    }

    return result;
}
}
<a asp-route-action="Create" class="btn btn-primary float-right" role="button">@T["Add Tenant"]</a>
<h1>@RenderTitleSegments(T["Tenants"])</h1>
<fieldset class="admin-toolbar container-fluid">
    <form asp-action="Index" method="get">
        <div class="row">
            <div class="col-md-1 col-xl-1 form-group">
                <label for="filterResults" class="label col-form-label">@T["Filter:"]</label>
            </div>
            <div class="col-md-3 col-xl-2 form-group">
                <select id="filterResults" class="form-control" asp-for="Options.Filter" asp-items="@tenantStates"></select>
            </div>
            <div class="col-md-3 col-xl-2 form-group">
                <input id="search-box" asp-for="Options.Search" class="form-control mr-sm-2 my-2 my-lg-0" type="text" placeholder="@T["Search"]" autofocus="autofocus">
            </div>
            <div class="col-md-3 col-xl-2 form-group">
                <select id="orderResults" class="form-control" asp-for="Options.OrderBy" asp-items="@tenantSorts"></select>
            </div>
            <div class="col-md-2 col-xl-1 form-group">
                <button type="submit" class="btn btn-secondary">@T["Search"]</button>
            </div>
        </div>
    </form>
</fieldset>

<form asp-action="Index" method="post">
    <fieldset class="admin-toolbar container-fluid">
        <div class="row">
            <div class="col-md-2 col-xl-1 form-group">
                <label for="bulkAction" class="label col-form-label">@T["Actions:"]</label>
            </div>
            <div class="col-md-3 col-xl-2 form-group">
                <select class="form-control" name="bulkAction" asp-items="@tenantActions"></select>
            </div>
            <div class="col-md-2 col-xl-1 form-group">
                <button type="submit" class="btn btn-secondary">@T["Apply"]</button>
            </div>
        </div>
    </fieldset>

    @* the form is necessary to generate and antiforgery token for the delete action *@
    <ul class="list-group">
        @foreach (var entry in Model.ShellSettingsEntries)
        {
            <li class="list-group-item">
                <div class="custom-control custom-checkbox float-left">
                    <input type="checkbox" class="custom-control-input" value="@entry.Name" name="tenantNames" id="tenantNames-@entry.Name">
                    <label class="custom-control-label" for="tenantNames-@entry.Name">&nbsp;</label>
                </div>
                <div class="properties">
                    <div class="related">
                        <a asp-action="Edit" asp-route-id="@entry.Name" class="btn btn-primary btn-sm">@T["Edit"]</a>
                        @if (!entry.IsDefaultTenant && entry.ShellSettings.State == TenantState.Running)
                        {
                            <a asp-action="Disable" asp-route-id="@entry.Name" class="btn btn-dark btn-sm" itemprop="UnsafeUrl">@T["Disable"]</a>
                        }
                        @if (entry.ShellSettings.State == TenantState.Disabled)
                        {
                            <a asp-action="Enable" asp-route-id="@entry.Name" class="btn btn-success btn-sm" itemprop="UnsafeUrl">@T["Enable"]</a>
                        }
                        @if (entry.ShellSettings.State == TenantState.Uninitialized)
                        {
                            <a class="btn btn-success btn-sm" id="btn-setup-@entry.Name" href="@GetTenantUrl(entry)">@T["Setup"]</a>
                        }
                        <a asp-action="Reload" asp-route-id="@entry.Name" class="btn btn-secondary btn-sm" itemprop="UnsafeUrl">@T["Reload"]</a>
                    </div>
                    <h5>
                        <a href="@GetTenantUrl(entry)">@entry.Name</a>
                        <code class="hint">@entry.ShellSettings.RequestUrlHost/@entry.ShellSettings.RequestUrlPrefix</code>
                        @switch (entry.ShellSettings.State)
                        {
                            case TenantState.Disabled:
                                <span class="badge badge-dark">@T["Disabled"]</span>
                                break;
                            case TenantState.Initializing:
                                <span class="badge badge-info">@T["Initializing"]</span>
                                break;
                            case TenantState.Invalid:
                                <span class="badge badge-warning">@T["Invalid"]</span>
                                break;
                            case TenantState.Running:
                                <span class="badge badge-success">@T["Running"]</span>
                                break;
                            case TenantState.Uninitialized:
                                <span class="badge badge-primary">@T["Uninitialized"]</span>
                                break;
                        }
                    </h5>
                </div>
            </li>
        }
    </ul>
</form>

@await DisplayAsync(Model.Pager)